<template>
    <div style="min-height: 100vh;background: #f5f5f5;padding-bottom: 50px">
        <div class="userMsg">
            <p class="topBar">货物详情<span><img src="@/assets/img/left.png" alt="" @click="backPrev"></span></p>
            <div class="userMessage">
                <span class="userImg"><img :src="data.user_image"></span>
                <p class="userNickName">
                    <span class="nickName">{{data.user_name}}</span>
                    <span class="userId">ID：{{data.user_ID}}</span>
                </p>
                <span class="userTel">
                    <img src="@/assets/img/tel.png" alt="">
                    <span>：{{data.user_phone}}</span>
                </span>
            </div>
        </div>
        <div style="padding: 0 4vw;background: #ffffff;padding-bottom:15px;margin-top:15px" v-if="type==1||type==2">
            <div class="checkedAll">
                <van-checkbox v-model="checkedAll" checked-color="#1ABC9C" @change="checkedAllFunc">全选</van-checkbox>
            </div>
            <van-checkbox-group v-model="result">
                <van-checkbox
                    v-for="(item, index) in data.list"
                    :key="index"
                    :name="item"
                    label-disabled
                    checked-color="#1ABC9C">
                    <div class="orderDetail">
                        <span class="goodsImg"><img :src="item.img" alt=""></span>
                        <div class="goodsText">
                            <p class="goodsName">{{item.name}}</p>
                            <p class="goodsSpec">{{item.spec_array}}</p>
                            <p class="artNo">货号：{{item.goods_no}}</p>
                            
                            <span class="goodsNum"><van-stepper v-model="item.number" @change="changeNum(item.number)" disable-input/></span>
                        </div>
                    </div>
                </van-checkbox>
            </van-checkbox-group>
        </div>
        <div v-else>
            <ul>
                <li v-for="(item, index) in data.list" :key="index">
                    <div class="orderDetail1">
                        <span class="goodsImg"><img :src="item.img" alt=""></span>
                        <div class="goodsText">
                            <p class="goodsName">{{item.name}}</p>
                            <p class="goodsSpec">{{item.spec_array}}</p>
                            <p class="artNo">货号：{{item.goods_no}}</p> 
                            <span class="goodsNum">X{{item.number}}</span>
                        </div>
                    </div>
                </li>
            </ul>   
        </div>
        <ul class="orderMsg">
            <li>订单号：{{data.order_no}}<button class="copyButton" type="button" @click="doCopy">复制</button></li>
            <li v-if="data.pay_type==1">支付宝：{{data.transaction_id}}</li>
            <li v-if="data.pay_type==2">微信支付：{{data.transaction_id}}</li>
            <li>下单时间：{{data.create_time}}</li>
            <li>付款时间：{{data.pay_time}}</li>
            <li v-if="type>=2">调货时间：{{data.transfer_time}}</li>
            <li v-if="type>=3">提货时间：{{data.send_library}}</li>
        </ul>
        <div class="bottomBar" v-if="type==1">
            <span v-if="result.length!=0">已选中{{result.length}}件商品</span>
            <button class="right" @click="checkedLoad">确认去调货</button>
        </div>
        <div class="bottomBar" v-if="type==2">
            <span v-if="result.length!=0">已选中{{result.length}}件商品</span>
            <button class="right" @click="checkedLoad">确认已调货</button>
        </div>
        <div class="bottomBar" style="padding-left:0px" v-else-if="type==3">
            <button style="width: 100vw;color: #ffffff;background:#1ABC9C" @click="checkedLoad">确认提货</button>
        </div>
    </div>
</template>
<script>
import PullTo from 'vue-pull-to';
import request from "@/request/index.js";
import { Toast } from 'vant';
export default {
    components:{
        PullTo
    },
    data(){
        return{
            list: ['a', 'b', 'c'],
            result: [],
            userMsg:{},
            order_no:'',
            data:{}, 
            checkedAll:false,
            order_goods:[],
            type:1,
            isLoading:true
        }
    },
    watch:{
        result(nVal,oVal){
            this.order_goods=[];
            nVal.forEach( (v,i)=> {
                this.order_goods.push({id:v.order_detail_id,number:v.number})
            });
        }
    },
    methods: {
        changeNum(num){
            this.order_goods.forEach((v,i)=>{
                this.result.forEach((v1,i1)=>{
                    if(v1.order_detail_id==v.id){
                        this.order_goods[i].number=num;
                    }
                })
            })
        },
        backPrev(){
            this.$router.go(-1)
        },
        doCopy: function () {
        this.$copyText(this.data.order_no).then(function (e){
          Toast({
            message:'复制成功'
          });
        }, function (e) {
          alert('Can not copy')
        })
      },
        checkedAllFunc(){
            if(this.checkedAll){
                this.result=this.data.list;
            }else{
                this.result=[];
            }
        },
        checkedLoad(){
            if(this.type==1){

            }else if(this.type==2){
                this.data.list.forEach( (v,i)=> {
                    this.order_goods.push({id:v.order_detail_id,number:v.number})
                });
            }
            if(this.order_goods.length>0){
                request.distribution(this)
            }else{
                Toast({
                    message:'请选择订单~~~'
                });
            }
            
        }
    },
    mounted(){
        this.type=this.$route.query.type;
        this.order_no=this.$route.query.order_no;
        request.selfLiftingDetails(this)
    }
}
</script>
<style scoped lang="scss">
.copyButton{
    color: #ffffff;
    background:#1ABC9C;
    padding: 0 10px;
    float:right;
    border-radius: 5px;
}
.bottomBar{
    position: fixed;
    width: 100vw;
    height: 50px;
    background: #ffffff;
    line-height: 50px;
    bottom: 0px;
    padding-left: 4vw;
    .right{
        float:right;
        background: #1ABC9C;
        color: #ffffff;
        padding: 0px 20px;
    }
}
.orderMsg{
    background: #ffffff;
    padding: 5px 4vw;
    margin-top: 15px;
    color: #666666;
    li{
        line-height: 27px;
    }
}
    .userMsg{
        background: #1ABC9C;
        color: #ffffff;
        .topBar{
            text-align:center;
            position: relative;
            line-height: 36px;
            padding: 0 4vw;
            vertical-align: middle;
            span{
                display: inline-block;
                position: absolute;
                height: 14px;
                width: 14px;
                left: 4vw;
                vertical-align: middle;
                img{
                    width: 100%;
                    height: 100%;
                }
            }
        }
        .userMessage{
            padding: 16px 4vw;
            position: relative;
            .userImg{
                width: 50px;
                height: 50px;
                display: inline-block;
                border-radius: 50%;
                overflow: hidden;
                vertical-align: middle;
                img{
                    width: 100%;
                    height: 100%;
                }
            }
            .userNickName{
                width: 200px;
                display: inline-block;
                vertical-align: middle;
                margin-left: 10px;
                span{
                    line-height: 25px;
                    display: block;
                }
            }
            .userTel{
                width: 150px;
                display: inline-block;
                position: absolute;
                right: 0px;
                bottom: 20px;
                vertical-align: middle;
                img{
                    height: 18px;
                    width: 18px;
                    vertical-align: middle;
                }
                span{
                    font-size: 13px;
                    vertical-align: middle;
                }
            }
        }
    }
    .orderDetail{
        vertical-align: middle;
        margin-top: 15px;
        background: #ffffff;

    }
    .orderDetail1{
        padding: 10px 4vw;
        margin-top: 15px;
        background: #ffffff;
    }
    .goodsImg{
        width: 100px;
        height:100px;
        float:left;

        img{
            height: 100%;
            width: 100%;
        }
    }
    .goodsText{
        width:66%;
        display: block;
        position: relative;
        margin-left: 110px;
        .goodsName{
            font-size: 13px;
            color:#333333;
            line-height: 18px;
            overflow: hidden;
            height: 36px;
            text-overflow: ellipsis;
        }
        .goodsSpec{
            font-size: 12px;
            color: #666666;
            margin-top: 10px;
            line-height: 17px;
            height: 27px;
        }
        .artNo{
            font-size: 12px;
            color: #666666;
            line-height: 17px;
            margin-top: 10px;
        }
        .goodsNum{
            color: #1ABC9C;
            position: absolute;
            right: 5px;
            bottom: 10px;
            font-size: 16px;
        }
    }
</style>


